package com.boang.thread;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/*
  @author: 13813
  @date: 2024/11/27 13:52
*/
public class ExecutorDemo {
    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                10, //核心线程数
                15, //最大线程
                30, //存活时间
                TimeUnit.MINUTES, //时间单位
                new ArrayBlockingQueue<>(5),
                //创建线程工厂
                //拒绝策略
                new ThreadPoolExecutor.DiscardPolicy()
        );

        //最大限量 15 + 5 = 20

        for (int i = 0; i < 25; i++) {
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName());
                }
            });
        }

    }
}
